package com.cn.wx.tread;

public class TreadOne extends Thread {

    /**
     * 当窗口售卖一张票时，我们的票就减少一张
     * 我们票list是唯一的
     */
    public TreadOne(String name, Tickets tickets) {
        super(name);
        this.tickets = tickets;
        this.name = name;
    }

    private Tickets tickets;
    private String name;
    private Object object="aa";

    @Override
    public void run() {
        while (tickets.list.size() > 0) {
//            tickets.getList(getName() + "卖出");
            synchronized (object) {
                if (tickets.list.size() > 0) {
                    System.out.println(name + tickets.list.get(0));
                    tickets.list.remove(0);
                } else {
                    System.out.println(name + "票已经卖完");
                }
            }
//            try {
//                sleep(1000);//休息一秒
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
        }

    }
}
